<?php
/**
  * CLOUD
  *
  * This is not a freeware, use is subject to license terms
  * @author CLOUD DEV TEAM
  * 
  */
class Lang
{
	/**
	 * 获取语言
	 * @param string|mix $module
	 * @throws BaseException
	 */
	public static function getLang( $module , $key = '' , $isCommon = false )
	{
		$LANG = array();
		$lang = Common::getConfig( 'System' , 'lang' ) ;
		$lang = $lang ? $lang : 'zh-cn';
		$newLang = $lang;
		if ( defined( "IN_CLOUD_ADMIN" ) && !$isCommon )
		{
			$newLang .= '/Admin';
		}
		if ( is_array( $module ) )
		{
			foreach ( $module as $value ) 
			{
				if ( file_exists( LANG . $newLang . '/' . ucfirst( $value ) . '.php' ) )
				{
					$NEWLANG = include LANG . $newLang . '/' . ucfirst( $value ) . '.php';
					if ( is_array( $NEWLANG ) )
					{
						$LANG = array_merge( $LANG , $NEWLANG );
					}
				}
				else
				{
					//$LANG = include LANG . $lang . '/' . 'ErrorCode.php';
					//throw new BaseException( BaseException::SYS_ERR_LANG_NOT_EXIST , $value . '--' . $LANG[BaseException::SYS_ERR_LANG_NOT_EXIST] );
					Common::errorOutput( $newLang . '/' . ucfirst( $value ) . '.php not exists!' );
				}
			}
			if ( empty( $key ) )
				return $LANG;
			else
				return $LANG[$key];
		}
		if ( file_exists( LANG . $newLang . '/' . ucfirst( $module ) . '.php' ) )
		{
			$LANG = include LANG . $newLang . '/' . ucfirst( $module ) . '.php';
			if ( empty( $key ) )
				return $LANG;
			else
				return $LANG[$key];
		}
		else
		{
			$LANG = include LANG . $lang . '/' . 'ErrorCode.php';
			throw new BaseException( BaseException::SYS_ERR_LANG_NOT_EXIST , $module . '--' . $LANG[BaseException::SYS_ERR_LANG_NOT_EXIST] );
		}
	}
}